﻿package src.components 
{
	
	/**
	* 
	* Reliability project
	* -----------------------
	* @author  Dmitrij Boycov
	* @mail    dmitry.boycov@gmail.com
	* @date    April 27, 2010
	* @version 1
	* 
	*/
	
	import flash.display.MovieClip;	
	import flash.events.MouseEvent;
	import flash.text.TextFormat;
	
	public class AbstractButton extends MovieClip{
		
		protected var textTooltip:String;
		protected var toolTip:ToolTip;
		
		/**
		 * constructor
		 */
		public function AbstractButton(){
			super();
			
			var tf:TextFormat = new TextFormat();
			tf.bold = true;
			tf.size = 12;
			tf.color = 0x0000ff;
			
			this.toolTip = new ToolTip();			
			this.toolTip.hook = false;
			this.toolTip.cornerRadius = 20;
			this.toolTip.align = "right";
			this.toolTip.autoSize = true;
			this.toolTip.titleFormat = tf;	
		}
		

		/**
		 * onMouseUp
		 * @param	e
		 */
		protected function onMouseUp(e:MouseEvent) {			
			e.target.gotoAndStop(1);
		}
		
		/**
		 * onMouseDown
		 * @param	e
		 */
		protected function onMouseDown(e:MouseEvent) {			
			e.target.gotoAndStop(3);
		}
		
		/**
		 * onMouseOver
		 * @param	e
		 */
		protected function onMouseOver(e:MouseEvent) {			
			e.target.gotoAndStop(2);
			if(this.textTooltip!=null){
				this.toolTip.show( this, this.textTooltip);
			}	
		}
		
		/**
		 * onMouseOut
		 * @param	e
		 */
		protected function onMouseOut(e:MouseEvent) {
			//this.gotoAndStop(1);
			e.target.gotoAndStop(1);
			if(this.textTooltip!=null){
				this.toolTip.hide();
			}	
		}
		
		public function setTooltip(text:String) {
			if(text!=''){
				this.textTooltip = text;
			}	
		}
		
	}
	
}